package main

import (
	"fmt"
)

/*
   Author: mahaiyuan
   Date: 2021/5/29 2:25 下午
   Description:
*/
func main() {
	ch := make(chan int, 10)
	go func() {
		for i := 0; i < 50; i++ {
			ch <- i + 1
			fmt.Println("success ", i)
		}
		close(ch)	//关闭通道
	}()
	//time.Sleep(time.Second)
	for data := range ch {	////关闭通道后会退出for range循环
		fmt.Println("receive data :", data)
		//time.Sleep(500 * time.Millisecond)
	}
	fmt.Println("main finish")
}